<?php

namespace app\miniapp\controller\v1;

use app\common\cachemodel\MiniAppUser;
use app\common\lib\exception\ApiException;
use app\common\model\User;
use app\miniapp\controller\AuthCheck;
use app\miniapp\controller\Common;

class Auth extends Common
{
    /**
     * 登录用户的基本信息
     * @var array
     */
    public $user = null;
    public $miniInfo = null;
    public $simulationLogin = false; // 是否账号模拟登陆

    protected function _initialize()
    {
        parent::_initialize();
        $authCheck = new AuthCheck();
        // 该接口是否可以免登陆
        $isExemptLogin = $authCheck->getIsExemptLogin(); // true可以免登陆 false必须登陆

        //如果不是免登陆的话，用户没有登录提示登录失效
        if (!$isExemptLogin && !$authCheck->isLogin())
        {
            throw new ApiException('登录失效', 200, config('code.denied'));
        }else{
            $authCheck->isLogin();//初始化user和miniInfo
        }

        $this->user = $authCheck->user;
        $this->miniInfo = $authCheck->miniInfo;
        $this->simulationLogin = $authCheck->simulationLogin;

        if ($this->user && $this->user['forbidden'] == 1)
        {
            throw new ApiException('登录失效', 200, config('code.denied'));
        }
    }
}
